package com.ruoyi.liaotian.controller;

import java.util.List;

import com.ruoyi.zhubo.domain.Anchor;
import com.ruoyi.zhubo.service.IAnchorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.liaotian.domain.Chatrecord;
import com.ruoyi.liaotian.service.IChatrecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 互动聊天管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-07
 */
@Controller
@RequestMapping("/liaotian/chatrecord")
public class ChatrecordController extends BaseController
{
    private String prefix = "liaotian/chatrecord";

    @Autowired
    private IAnchorService anchorService;

    @Autowired
    private IChatrecordService chatrecordService;

    @RequiresPermissions("liaotian:chatrecord:view")
    @GetMapping()
    public String chatrecord()
    {
        return prefix + "/chatrecord";
    }

    /**
     * 查询互动聊天管理列表
     */
    @RequiresPermissions("liaotian:chatrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Chatrecord chatrecord)
    {
        startPage();
        List<Chatrecord> list = chatrecordService.selectChatrecordList(chatrecord);
        return getDataTable(list);
    }

    /**
     * 导出互动聊天管理列表
     */
    @RequiresPermissions("liaotian:chatrecord:export")
    @Log(title = "互动聊天管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Chatrecord chatrecord)
    {
        List<Chatrecord> list = chatrecordService.selectChatrecordList(chatrecord);
        ExcelUtil<Chatrecord> util = new ExcelUtil<Chatrecord>(Chatrecord.class);
        return util.exportExcel(list, "互动聊天管理数据");
    }

    /**
     * 新增互动聊天管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存互动聊天管理
     */
    @RequiresPermissions("liaotian:chatrecord:add")
    @Log(title = "互动聊天管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Chatrecord chatrecord)
    {
        return toAjax(chatrecordService.insertChatrecord(chatrecord));
    }

    /**
     * 修改互动聊天管理
     */
    @RequiresPermissions("liaotian:chatrecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Chatrecord chatrecord = chatrecordService.selectChatrecordById(id);
        mmap.put("chatrecord", chatrecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存互动聊天管理
     */
    @RequiresPermissions("liaotian:chatrecord:edit")
    @Log(title = "互动聊天管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Chatrecord chatrecord)
    {
        return toAjax(chatrecordService.updateChatrecord(chatrecord));
    }

    /**
     * 删除互动聊天管理
     */
    @RequiresPermissions("liaotian:chatrecord:remove")
    @Log(title = "互动聊天管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatrecordService.deleteChatrecordByIds(ids));
    }

    /**
     * 接收者，发送者
     */
    @GetMapping("/senderList")
    @ResponseBody
    public List<Anchor> getSenderList(Anchor anchor) {
        return anchorService.selectAnchorList(anchor);
    }





}
